from datetime import datetime
from exceptions import LiquidRenderError
from constants import EMPTY_REPLACEMENT
from filters.manager import FilterManager


@FilterManager.register
def date(dt_format: str, value: str):
    if isinstance(value, str):
        dt = datetime.fromtimestamp(value)
        return dt.strftime(dt_format)
    raise LiquidRenderError(value)
